<?php
/**
 * Created by PhpStorm.
 * User: Dell
 * Date: 2018-12-10
 * Time: 15:15
 */

namespace app\common\model;


use think\Model;

class MessageModel extends Model
{
    // 确定链接表名
    protected $name = 'message';
    /**
     * 查询留言
     * @param $where
     * @param $offset
     * @param $limit
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getMessageByWhere($where, $offset, $limit)
    {
        return $this->where($where)->limit($offset, $limit)->order('mess_id desc')->select();
    }

    /**
     * @param $where
     * @return int|string
     */
    public function getAllMessage($where)
    {
        return $this->where($where)->count();
    }

    public function addMessage($param)
    {
        try{
            $result = $this->validate('MessageValidate')->save($param);
            if(false === $result){
                // 验证失败 输出错误信息
                return msg(-1, '', $this->getError());
            }else{

                return msg(1, url('message/index'), '添加文章成功');
            }
        }catch (\Exception $e){
            return msg(-2, '', $e->getMessage());
        }
    }
}